home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qbsub10.arc / FILTER.SUB < prev    next >
Encoding:
Text File  |  1986-06-24  |  3.4 KB  |  107 lines

  1. 'FILTER.SUB -- MSDOS QuickBASIC string filter subroutines    25 June 86
  2. '        by David L. Poskie     (608) 274-9560
  3. '                  7118 Raymond Rd. Madison, WI 53719
  4. ' Please run any suggestions, corrections, additions, or changes by me.
  5. ' I can be messaged on all the major Madison, WI RBBS's.
  6.  
  7. '| Filter subroutines:
  8. '|     FilterSpaceTab -- removes leading spaces & TABS in Text$
  9. '|    FilterNonAlpha -- removes leading non-alphabetic characters in Text$
  10. '|    FilterNonNumeric   -- removes leading non-numeric characters in Text$ 
  11. '|    FilterCheck    -- removes what's in Check$ from front of Text$
  12. '|    FilterCheckTail -- removes what's in Check$ from tail of Text$
  13. '| NOTE: The Check filters are universal, letting you remove ANY character/s.  
  14. '|
  15. '| >>> See the specific routines for more information.
  16. '|
  17. '|  Input: unfiltered Text$
  18. '|         Check$ (if using FilterCheck or FilterCheckTail)
  19. '| Output:   filtered Text$ or error message & unaltered Text$
  20.  
  21. '  ________________________ FILTER SUBROUTINES __________________________
  22.  
  23.     ' Filter any extra leading spaces and TABs from Text$
  24. FilterSpaceTab:
  25.     ' Check for null Text$ error
  26.     GOSUB TextError
  27.     ' Isn't this elegant ?
  28.     WHILE ASC(Text$) = 9                        _
  29.        OR ASC(Text$) = 32
  30.           Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
  31.           GOSUB TextError
  32.     WEND
  33. GOTO FilterExit
  34.  
  35.     ' Filter any leading non-alphabetic characters
  36. FilterNonAlpha:
  37.     ' Check for null Text$
  38.     GOSUB TextError
  39.     ' I love it !
  40.     WHILE ASC(Text$) < 65                         _
  41.       OR (ASC(Text$) > 90 AND ASC(Text$) < 97)            _
  42.          OR ASC(Text$) > 122
  43.           Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
  44.           GOSUB TextError
  45.     WEND
  46. GOTO FilterExit
  47.  
  48.     ' Filter any leading non-number characters
  49. FilterNonNumeric:
  50.     ' Prepare for possible error
  51.     GOSUB TextError
  52.     ' Yeah.
  53.     WHILE ASC(Text$) < 48                        _
  54.        OR ASC(Text$) > 57
  55.           Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
  56.           GOSUB TextError
  57.     WEND
  58. GOTO FilterExit
  59.  
  60.     ' Filter Text$ for any leading instance of the string variable, Check$
  61.     ' NOTE:
  62.     ' Check$ could be a single character, making this a universal filter.
  63. FilterCheck:
  64.     ' Prepare for possible error
  65.     GOSUB TextError
  66.     GOSUB CheckError
  67.     ' Easy.
  68.     WHILE LEFT$(Text$ , LEN(Check$)) = Check$
  69.           Text$ = RIGHT$(Text$ , LEN(Text$) - LEN(Check$))
  70.           GOSUB TextError
  71.     WEND
  72. GOTO FilterExit
  73.  
  74.     ' Filter Text$ for any trailing instance of the string variable, Check$
  75.     ' NOTE:
  76.     ' Check$ could be any character/s, making this a universal filter.
  77. FilterCheckTail:
  78.     ' Test for null Check$ or null Text$ errors
  79.     GOSUB CheckError
  80.     ' Save Text$ in case there isn't a perfect match
  81.     Temp$ = Text$
  82.     ' Reverse the Check$ checking
  83.     FOR Num = LEN(Check$) TO 1 STEP -1
  84.         IF RIGHT$(Text$ , 1) = MID$(Check$ , Num , 1)        _
  85.            THEN Text$ = LEFT$(Text$ , LEN(Text$) - 1) :        _
  86.     NEXT Num
  87.     'Restore Text$, if not a complete match
  88.     IF Num > 0 THEN Text$ = Temp$
  89.           GOSUB TextError
  90. GOTO FilterExit
  91.  
  92.     ' Error trapping local subroutines (These could be expanded).
  93.     ' They could be used in the main program if you've $Included this file.
  94.     ' Check for empty Check$
  95. CheckError:
  96.     IF Check$ = ""                            _
  97.        THEN PRINT "Check$ empty error"
  98.     ' Check for empty Text$
  99. TextError:
  100.     IF Text$ = ""                            _
  101.        THEN PRINT "Text$ empty error"
  102.  
  103.     ' Common exit point for all filter subroutines
  104. FilterExit:
  105. RETURN
  106. ' >>>>> Physical EOF FILTER.SUB  25 June 86
  107.